#ifndef ETTADATASTRUCT_H
#define ETTADATASTRUCT_H
#include <QString>
#include <QMetaType>
#include <QVariant>

enum EttaError
{
    UNKNOWN_ERROR = -1,
    OK = 0,
    LOGIN_ERROR,
    LOGIN_USER_PW_MISMATCH,
    LOGIN_NO_USER,
    LOGIN_USER_DISABLED,
    LOGIN_ACCOUNT_LOCKED,
    CREATE_TABLE_ERROR,
    UPDATE_TABLE_ERROR,
    INSERT_TABLE_ERROR,
    EXP_VOLUME_EMPTY,
    EXP_SAMPLE_EMPTY,
    EXP_SAMPLE_ALREADY_EXIST,
    EXP_MATERIAL_EXPIRE,
    EXP_MATERIAL_NOT_MATCH,
    EXP_MATERIAL_ALREADY_EXIST,
    EXP_MATERIAL_INVALID,
    EXP_MATERIAL_EMPTY,
    EXP_PARAM_UNSELECTED,
    ROLE_NAME_EMPTY,
    ROLE_NAME_INNER_USER,
    ROLE_ALREADY_EXIST,
    ROLE_NAME_LENGTH_ERROR,
    ROLE_INSERT_FAIL,
    ROLE_DELETE_FAIL,
    USER_INSERT_FAIL,
    USER_DELETE_FAIL,
    CTRL_ERROR_8001 = 8001,
    CTRL_ERROR_8002,
    CTRL_ERROR_8003,
    CTRL_ERROR_8004,
    CTRL_ERROR_8005,
    CTRL_ERROR_8006,
    CTRL_ERROR_8007,
    CTRL_ERROR_8008,
    CTRL_ERROR_8009,
    CTRL_ERROR_8010,
    CTRL_ERROR_8011,
    CTRL_ERROR_8012,
    CTRL_ERROR_8013,
    CTRL_ERROR_8014,
    CTRL_ERROR_8015,
    CTRL_ERROR_8016,
};

enum MainPageIndex
{
    STARTUP=0,
    LOGIN=1,
    MAIN=2,
    DATA,
    EXPERIMENT,
    CONFIG,
    REPORT
};

enum ConfigPageIndex
{
    PARAM_SET=0,
    PERFORMANCE,
    SYSTEM_LOG,
    SYSTEM_CONFIG,
    USER_MANAGE,
    ABOUT,
    SYSTEM_UPDATE,
    FACTORY,
};

enum SystemConfigIndex
{
    USERNAME=0,
    PASSWORD,
    NETWORK,
    PRINT_SET,
    TIME_SET,
    LANGUAGE,
};

enum FactoryConfigIndex
{
    OSCILLOSCOPE=0,
    VOLTAGE,
    FLOWRATE,
    MOTOR,
    PRODUCT,
    DEBUG,
};

enum AboutPageIndex
{
    LOCAL_INFO=0,
    MANUAL,
    TECHNIQUE,
    TIPS,
    WEBSITE,
};

enum TableIndex
{
    T_USER,
    T_ROLE,
    T_PARAMETER,
    T_EXPERIMENT,
    T_SAMPLE,
    T_MATERIAL,
    T_LOG,
    T_FLOW_TEST,
    T_VOLT_TEST,
    T_MATERIAL_CODE,
    T_VERSION
};

struct User
{
    QString name;
    QString password;
    QString role;
    QString createDatetime;
    QString remark;
    int permission;
    int status;
    int failLoginTimes;
};

struct Role
{
    QString name;
    int permission;
    QString createDatetime;
};

struct Sample
{
    QString name;
};

struct Material
{
    QString name;
    QString type;
    QString batchNumber;
    QString serialCode;
    QString expirationDate;
};

enum ParameterIndex{
    PARAM_NAME=0,
    PARAM_CODE,
    PARAM_VOLT,
    PARAM_PULSE,
    PARAM_INTERVAL,
    PARAM_SPEED,
    PARAM_TIMES,
    PARAM_ISON,
};

struct Parameter
{
    QString name;
    QString code;
    double volt;
    double pulse;
    double interval;
    double speed;
    double times;
    bool ison;
};

struct ExperimentInfo
{
    QString username;
    QString datetimeExpStart;
    QString datetimeExpEnd;
    QString parameterName;
    QString parameterCode;
    QString sampleName;
    QString materialISN;
    QString duration;
    QString result;
    QString voltageRmsDatapath;
    QString specifications;
    QString batchNumber;
    double volume;
    int voltage;
    int pulse;
};

enum ExperimentInfoIndex
{
    EXP_USERNAME,
    EXP_DATETIME_START,
    EXP_DATETIME_END,
    EXP_PARAMETER_NAME,
    EXP_PARAMETER_CODE,
    EXP_SAMPLE_NAME,
    EXP_MATERIAL_ISN,
    EXP_DURATION,
    EXP_RESULT,
    EXP_VOLUME,
    EXP_DATAPATH,
    EXP_SPECIFICATIONS,
    EXP_BATCH_NUMBER,
    EXP_VOLTAGE,
    EXP_PULSE,
};

enum LogType
{
    OPERATION = 0,
    ERROR_LOG = 2,
};

struct LogInfo
{
    QString datetime;
    QString username;
    LogType type;
    QString code;
    QString detail;
};

enum LogInfoIndex{
    LOG_DATETIME,
    LOG_USERNAME,
    LOG_TYPE,
    LOG_DETAIL,
};

enum CMD_TYPE
{
    DETECT,HP2PAR,SHOCHK,HP2STR,HP2STP,RDBSTR,RDBSTP,SHAOPN,SHASTP,PWRCHK,FLWCHK,PWROFF,LQDVOL,VERNUM,ROTCAL,SHACAL,LEDCTL,XZDJSZ,XZDJSN,HP3STR
};

enum class LedType
{
    Red = 'R', Green = 'G', Blue = 'B'
};

enum class Status
{
    Startup,    // 开机中
    Idle,       // 空闲待机
    Experiment, // 实验中
    Busy,       // 忙碌中
    Error,      // 故障
    MotorCalib, // 电机校准中
};

struct SHK_Result
{
    CMD_TYPE type;
    int ret;
    QString info;
};

struct FinishMessage
{
    int flowTimediff;
    QString message;
};

struct HostReply
{
    QString cmd;
    CMD_TYPE type;
    QString message;
    QString tips;
    QVariant parameter;
};

struct IMeasureData {};

template <typename T>
struct MeasureMetaData
{
    T setValue;
    T realValue;
};

struct VoltTest : public IMeasureData
{
    QString datetime;
    QString username;
    MeasureMetaData<double> lowVolt;
    MeasureMetaData<double> mediumVolt;
    MeasureMetaData<double> highVolt;
    MeasureMetaData<double> lowPulseWidth;
    MeasureMetaData<double> mediumPulseWidth;
    MeasureMetaData<double> highPulseWidth;
};

struct FlowTest : public IMeasureData
{
    QString datetime;
    QString username;
    double volume;
    MeasureMetaData<double> flow;
};

enum VoltTestIndex
{
    VOLT_DATETIME = 0,
    VOLT_USERNAME,
    VOLT_LOW_VOLT_SET,
    VOLT_LOW_VOLT_REAL,
    VOLT_MEDIUM_VOLT_SET,
    VOLT_MEDIUM_VOLT_REAL,
    VOLT_HIGH_VOLT_SET,
    VOLT_HIGH_VOLT_REAL,
    VOLT_LOW_PULSE_WIDTH_SET,
    VOLT_LOW_PULSE_WIDTH_REAL,
    VOLT_MEDIUM_PULSE_WIDTH_SET,
    VOLT_MEDIUM_PULSE_WIDTH_REAL,
    VOLT_HIGH_PULSE_WIDTH_SET,
    VOLT_HIGH_PULSE_WIDTH_REAL,
};

enum FlowTestIndex
{
    FLOW_DATETIME = 0,
    FLOW_USERNAME,
    FLOW_VOLUME_SET,
    FLOW_SET,
    FLOW_REAL,
};

struct ComCmd{
    CMD_TYPE type;
    int value1;
    int value2;
    int value3;
    int value4;
    int value5;
};

enum ReportType{
    LOG_REPORT=0,
    DATA_REPROT,
    PERF_VOLT_REPORT,
    PERF_FLOW_REPORT,
    PRINT_TEPLATE_REPORT,
    EXPERIMENT_REPORT,
    FACTORY_DATA,
};

enum TimeSetType{
    DATA_START = 0,
    LOG_START,
    SET_TIME,
    PERFORMANCE_VOLT,
    PERFORMANCE_FLOW,
};

Q_DECLARE_METATYPE(LedType)
Q_DECLARE_METATYPE(CMD_TYPE)
Q_DECLARE_METATYPE(ComCmd)
Q_DECLARE_METATYPE(SHK_Result)
Q_DECLARE_METATYPE(FinishMessage)
Q_DECLARE_METATYPE(HostReply)

#endif // ETTADATASTRUCT_H
